<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="editForm">

        <div class="layui-form-item">
            <label class="layui-form-label required">帐号</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="">
                <input type="text" name="account" disabled value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男"/>
                <input type="radio" name="gender" value="0" title="女"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">年龄</label>
            <div class="layui-input-block">
                <input type="number" name="age" lay-verify="required|age" lay-reqtext="年龄不能为空" placeholder="请输入年龄" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">手机</label>
            <div class="layui-input-block">
                <input type="number" name="phone" lay-verify="required|phone" lay-reqtext="手机不能为空" placeholder="请输入手机号码" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" lay-verify="required|email" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'axios'], function () {
        var form = layui.form,
            layer = layui.layer,
            axios = layui.axios,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.verify({
            age: function (value, item) {
                if (value <= 0 || value > 150){
                    return "年龄数值不合理";
                }
            }
        });
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let obj = data.field;

            //异步提交修改
            axios({
                method: "post",
                url: "family/updateMember",
                data: obj
            }).then(response => {
                if (response.code == 0){
                    layer.msg(response.msg, function (){
                        layui.table.reload("currentTableId");
                        layer.close(parentIndex);
                    })
                }else{
                    layer.msg(response.msg);
                }

            }).catch(error => {
                console.log(error);
            })
            return false;
        });

    });
</script>